package uk.ac.aber.paws.client.pendrivechecker;

import java.util.Hashtable;
import java.util.Vector;

import uk.ac.aber.paws.client.config.ConfigManager;
import uk.ac.aber.paws.client.constants.Constants;
import uk.ac.aber.paws.client.logmeout.LogMeOut;
import uk.ac.aber.paws.client.util.WMIOperations;

/**
 * @author Rob Johnson, Aberystwyth University
 * @email rob.johnson@aber.ac.uk
 * @date 16th August 2011
 * 
 * PenDriveChecker.java
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

public class PenDriveChecker {

	private static ConfigManager mainConfig;
	
	public static void main (String args[]) {
		
		mainConfig = new ConfigManager(args[0],null,false);
		
		checkNow();
		
	}
	
	public static ConfigManager getMainConfig() {
		
		return mainConfig;
	}
	
	private static void checkNow() {
	
		Vector<Hashtable<String,String>> volumeList = WMIOperations.getVolumeList();
		
		for (int i=0;i<volumeList.size();i++) {
			
			Hashtable<String,String> tmpHash = volumeList.get(i);
			
			String drives = "";
			boolean penDrive = false;
			
			// found a pen drive - warn them!
			if (Integer.parseInt(tmpHash.get("DriveType")) ==  Constants.PENDRIVE_IDENTIFIER_ID) {
				penDrive = true;
				drives += tmpHash.get("DriveLetter")+"    ";
			}
			
			if (penDrive) {
				(new WarningWindow("en",false,drives.substring(0,drives.length()-1))).setVisible(true);
			}
		}
	}
	
}
